package T01_案例入门;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * 一、快速入门实现
 * 1.快速入门步骤
 *     ①导入数据库驱动jar包
 *        1.复制mysql-connector-java-5.1.37-bin.jar到项目的libs目录下
 *        2.右键-->Add  As  Library
 *     ②注册驱动(这一步可以省略)
 *     ③获取数据库连接对象 Connection
 *     ④定义sql
 *     ⑤获取执行SQL语句的对象 Statement
 *     ⑥执行SQL,接收返回结果
 *     ⑦处理结果
 *     ⑧释放资源
 */
public class IntroductionToCase {
    public static void main(String[] args) throws Exception {

        //1. 导入驱动jar包

        //2.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //3.获取数据库连接对象("jdbc:mysql://localhost:3306/db3", "root", "root")
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3309/test?useSSL=false", "root", "root");
        //4.定义sql语句
        String sql = "insert into  `user` (`name`,`password`,`address`,`phone`) values('侯茂昌','1234','邯郸翱翔','15630051326')";
        //5.获取执行sql的对象 Statement
        Statement stmt = conn.createStatement();
        //6.执行sql
        int count = stmt.executeUpdate(sql);
        //7.处理结果
        System.out.println(count);
        //8.释放资源
        stmt.close();
        conn.close();
    }
}
